package cn.powerone.scm.mapper;

import java.util.Date;
import java.util.List;
import cn.powerone.scm.domain.ScmProducts;
import cn.powerone.scm.domain.ScmProductsSub;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

/**
 * 产品Mapper接口
 * 
 * @author PowerOne
 * @date 2025-06-27
 */
public interface ScmProductsMapper 
{
    /**
     * 查询产品
     * 
     * @param id 产品主键
     * @return 产品
     */
    public ScmProducts selectScmProductsById(Long id);

    /**
     * 查询产品列表
     * 
     * @param scmProducts 产品
     * @return 产品集合
     */
    public List<ScmProducts> selectScmProductsList(ScmProducts scmProducts);

    /**
     * 新增产品
     * 
     * @param scmProducts 产品
     * @return 结果
     */
    public int insertScmProducts(ScmProducts scmProducts);

    /**
     * 修改产品
     * 
     * @param scmProducts 产品
     * @return 结果
     */
    public int updateScmProducts(ScmProducts scmProducts);

    /**
     * 删除产品
     * 
     * @param id 产品主键
     * @return 结果
     */
    public int deleteScmProductsById(Long id);

    /**
     * 批量删除产品
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteScmProductsByIds(Long[] ids);

    /**
     * 批量删除产品子表
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteScmProductsSubByProductIds(Long[] ids);
    
    /**
     * 批量新增产品子表
     * 
     * @param scmProductsSubList 产品子表列表
     * @return 结果
     */
    public int batchScmProductsSub(List<ScmProductsSub> scmProductsSubList);
    

    /**
     * 通过产品主键删除产品子表信息
     * 
     * @param id 产品ID
     * @return 结果
     */
    public int deleteScmProductsSubByProductId(Long id);

    public ScmProducts selectScmProductsByDrawingNumber(String drawingNumber);

    public List<ScmProducts> selectScmProductsByParentId(long oldId);


    @Select("SELECT COUNT(*) FROM scm_products WHERE YEAR(create_time) = YEAR(#{yesterday}) AND MONTH(create_time) = MONTH(#{yesterday})")
    @Options(useCache = false, flushCache = Options.FlushCachePolicy.TRUE)
    public int selectProductsCountByMonth(Date yesterday);

    @Select("SELECT COUNT(*) FROM scm_products WHERE YEAR(create_time) = YEAR(#{yesterday})")
    @Options(useCache = false, flushCache = Options.FlushCachePolicy.TRUE)
    public int selectProductsCountByYear(Date yesterday);

    @Select("SELECT COUNT(*) FROM scm_products")
    @Options(useCache = false, flushCache = Options.FlushCachePolicy.TRUE)
    public int selectProductsCountAll();
}
